<template>
	<view class="content">
		<!-- <view class="text-area">
			加密：<span class="title">{{enText}}</span>
		</view>
		<view class="text-area">
			解密：<span class="title">{{deText}}</span>
		</view>
		<view @click="doCrypt">
			加密
		</view>
		<view @click="doDecrypt">
			解密
		</view>
		
		<view @click="onSubmit">
			测试完整加密
		</view>
		
		<view @click="takepick">
			拍照
		</view> -->

	</view>
</template>

<script>
	// import { aesDecrypt, aesEncrypt } from "@/utils/aesCrypt";
	// import { rsaEncrypt, rsaDecrypt } from "@/utils/rsaCrypt";
	// import { base64Encode, Base64Decode } from "@/utils/base64";
	// import CryptoJS from 'crypto-js';
	// import Base64 from 'js-base64'; // 引入库
	// const secretKey = "mySecretKey123";

	import {aesEncrypt, aesDecrypt } from '@/encrypt/AES/aes';
	import { base64Encode,base64Decode } from '@/encrypt/Base64/base64';
	import { rsaEncrypt, rsaDecrypt} from '@/encrypt/RSA/rsa';
	const prikey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDd8bqiWK6kD9vIwyuBMW70Ha9VwB+w533ZbP08V5SGmsiaoXnScL5q3YYC8gnsk8un5pH2Xx4znXEFNTM+qYENIvGVM0HkpySNfQ7+qaOxWmCEFjlqmBqknei7Efk5Sn4i5ZuXe/2/rbUszDP2ZrusaCqquerYpJEJqo/Q5XokUQIDAQAB';
	
	export default {
		data() {
			return {
				text: 'Hello, World!',
				enText: '',
				deText: ''
			}
		},
		onLoad() {
			
			const deBase64Key1 = 'QWxDVUoxQmhxRmRKc1V2MUdmajJjd0FoRUpwUll0eWYydko4Wmc4TEkwNFlaQ2N5S2ZaVm5SS05jOUJsYzVzbQ0KSzNQUHpKdWxHbDl0NlFaTGh5SU4vRTlYTXM1cllidjlJRS9hNkxZeDFzWDVrVXp1VGlBRktza1BEdVFCTUlYTg0KTjhxa1J0TEtRZFpJVklZT2tMOFVxakF1Q1AyRjMwVzlBQ1YrVlNzSGxac21uRFVLRGJ6ekR0T1lsV1FEdWdheA0KZU1hSVVXWEhTekF2TzRtKzJ5c0hKNm9KTlBOVWorT3ZkZ1gyLzl3bGNMa0xydEFkRUNUZlJDTEZnbGNlMEZ0MA==';
			const debase64data1 = base64Decode(deBase64Key1); // 解码，同理使用库的方法进行解码或编码。例如Base64.decodeURI()用于URL安全的Base64解码。
			
			console.log("debase64data1",debase64data1);
			
			const token = 'a2YyNWh1K3FISmxubTVkU0VRcFFzaW42WFR5YVIwNFM3WGIvTFJNT2pWZHB2RXlBek16UEhtVGw3cEtQN2x0NDJwbC9WbE1EQkpLWkRQWkJxU2FjdktvM2FLYi9NZnR5cWJQZ0dHOVpMRnI3emlqOE9NZUg1NVk5a09BYVcvdVRYUzFFZ2NOQ3VVTWFra01rWlZzUWFGTkdKMExiODZwOW04MVdHckd5OERvPQ=='
			const uuid = '0F078A74-B8EC-4DB0-A186-741B89A5EA00';
			const params = {
				content: '123',
				ios_type: 2,
				phone: '9888888555',
				picture: '',
				type: 1,
				unique_mid: uuid,
				version: '1.0.0'
			}
			
			// {
			//     key = "TnhiU1RPa0FWMncyVXM2dVVQdzVRRllWSVp0MHVtVHdzalNuK29aNU12NmRRRjJvbEM3YUFGYTVIWWd4UE1zZmdBYTkwWG5rdWxIZWttOXJWTTBNOEV1SkJEMlRzMnFLa25IdCtTVXg1WmRpYjQrNXpqSDdtSmRHWHpQbXpGUk5HYmgvRnFsVlp6Q2dlTm96aFVDYXlySjdNRHNmUUd5V2ZaZzczRVBBdUVBPQ==";
			//     "mgc_data" = "QWxDVUoxQmhxRmRKc1V2MUdmajJjd0FoRUpwUll0eWYydko4Wmc4TEkwNFlaQ2N5S2ZaVm5SS05jOUJsYzVzbQ0KSzNQUHpKdWxHbDl0NlFaTGh5SU4vRTlYTXM1cllidjlJRS9hNkxZeDFzWDVrVXp1VGlBRktza1BEdVFCTUlYTg0KTjhxa1J0TEtRZFpJVklZT2tMOFVxakF1Q1AyRjMwVzlBQ1YrVlNzSGxac21uRFVLRGJ6ekR0T1lsV1FEdWdheA0KZU1hSVVXWEhTekF2TzRtKzJ5c0hKNm9KTlBOVWorT3ZkZ1gyLzl3bGNMa0xydEFkRUNUZlJDTEZnbGNlMEZ0MA==";
			//     token = "a2YyNWh1K3FISmxubTVkU0VRcFFzaW42WFR5YVIwNFM3WGIvTFJNT2pWZHB2RXlBek16UEhtVGw3cEtQN2x0NDJwbC9WbE1EQkpLWkRQWkJxU2FjdktvM2FLYi9NZnR5cWJQZ0dHOVpMRnI3emlqOE9NZUg1NVk5a09BYVcvdVRYUzFFZ2NOQ3VVTWFra01rWlZzUWFGTkdKMExiODZwOW04MVdHckd5OERvPQ==";
			// }
			const jsonString = JSON.stringify(params);
			console.log("jsonString====",jsonString);
			const enText = aesEncrypt('111',uuid);
			console.log("enText====",enText);
			// U2FsdGVkX19nQkiMRhTHUEmprQN4XFVTUb/VlZIAQBo=
			// U2FsdGVkX18qsClJHhoTmJTuA+w0lyRvSEuXa/1PX9E=
			
		
				
			const enData = base64Encode(enText);
			console.log("enText=base64Encode===",enData);
			const enRsaText = rsaEncrypt(prikey,uuid);
			
			console.log("enRsaText====",enRsaText);
			
			const enBase64Text = base64Encode(enRsaText);
			const enBase64 = base64Encode(enBase64Text);
			
			let req = {
				key: enBase64,
				mgc_data: enData,
				token: token,
			}
			uni.request({
				url:'https://api.jetpso.com/Sv/Question/insert',
				method: 'POST',
				header: {
					'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
					'token': token,
				},
				data: req,
				timeout: 30000,
			}).then(res=>{
				console.log("res====",res);
			}).catch(err=>{
				console.log('err=====',err);
			})
		},
		methods: {
			doCrypt(){
				// const encryptedText = encrypt(this.text, secretKey);
				// this.enText = encryptedText;
				// console.log('Encrypted:', encryptedText);
				
				// const decryptedText = decrypt(this.enText, secretKey);
				// this.deText = decryptedText;
				// console.log('Decrypted:', decryptedText);
				
				
				console.log("CryptoJS.AES====333=",CryptoJS.mode);
				console.log("CryptoJS.AES====pad=",CryptoJS.pad.Pkcs7);
				
				// 加密
				const message = "Hello, CryptoJS!";
				const key = "my-secret-key";
				const encrypted = CryptoJS.AES.encrypt(message, key,{
					mode: CryptoJS.mode.CBC,
					padding: CryptoJS.pad.Pkcs7
				}).toString();
				console.log("加密后的数据:", encrypted);
				
				// 解密
				const decrypted = CryptoJS.AES.decrypt(encrypted, key,{
					mode: CryptoJS.mode.CBC,
					padding: CryptoJS.pad.Pkcs7
				});
				const decryptedMessage = decrypted.toString(CryptoJS.enc.Utf8);
				console.log("解密后的数据:", decryptedMessage);
				
			},
			doDecrypt(){
				// const decryptedText = decrypt(this.enText, secretKey);
				// this.deText = decryptedText;
				// console.log('Decrypted:', decryptedText);
				
				
				
			},
			takepick(){
				uni.chooseImage({
				  sourceType: ['camera'],
				  success(res) {
				    console.log('拍照成功', res.tempFilePaths);
				  }
				});

			},
			onSubmit(){
				
				
				const deBase64Key1 = 'QWxDVUoxQmhxRmRKc1V2MUdmajJjd0FoRUpwUll0eWYydko4Wmc4TEkwNFlaQ2N5S2ZaVm5SS05jOUJsYzVzbQ0KSzNQUHpKdWxHbDl0NlFaTGh5SU4vRTlYTXM1cllidjlJRS9hNkxZeDFzWDVrVXp1VGlBRktza1BEdVFCTUlYTg0KTjhxa1J0TEtRZFpJVklZT2tMOFVxakF1Q1AyRjMwVzlBQ1YrVlNzSGxac21uRFVLRGJ6ekR0T1lsV1FEdWdheA0KZU1hSVVXWEhTekF2TzRtKzJ5c0hKNm9KTlBOVWorT3ZkZ1gyLzl3bGNMa0xydEFkRUNUZlJDTEZnbGNlMEZ0MA==';
				const debase64data1 = Base64.decode(deBase64Key1); // 解码，同理使用库的方法进行解码或编码。例如Base64.decodeURI()用于URL安全的Base64解码。
				
				console.log("debase64data1",debase64data1);
				
				const token = 'a2YyNWh1K3FISmxubTVkU0VRcFFzaW42WFR5YVIwNFM3WGIvTFJNT2pWZHB2RXlBek16UEhtVGw3cEtQN2x0NDJwbC9WbE1EQkpLWkRQWkJxU2FjdktvM2FLYi9NZnR5cWJQZ0dHOVpMRnI3emlqOE9NZUg1NVk5a09BYVcvdVRYUzFFZ2NOQ3VVTWFra01rWlZzUWFGTkdKMExiODZwOW04MVdHckd5OERvPQ=='
				const uuid = '0F078A74-B8EC-4DB0-A186-741B89A5EA00';
				const params = {
					content: '123',
					ios_type: 2,
					phone: '9888888555',
					picture: '',
					type: 1,
				    unique_mid: uuid,
					version: '1.0.0'
				}
				
				// {
				//     key = "TnhiU1RPa0FWMncyVXM2dVVQdzVRRllWSVp0MHVtVHdzalNuK29aNU12NmRRRjJvbEM3YUFGYTVIWWd4UE1zZmdBYTkwWG5rdWxIZWttOXJWTTBNOEV1SkJEMlRzMnFLa25IdCtTVXg1WmRpYjQrNXpqSDdtSmRHWHpQbXpGUk5HYmgvRnFsVlp6Q2dlTm96aFVDYXlySjdNRHNmUUd5V2ZaZzczRVBBdUVBPQ==";
				//     "mgc_data" = "QWxDVUoxQmhxRmRKc1V2MUdmajJjd0FoRUpwUll0eWYydko4Wmc4TEkwNFlaQ2N5S2ZaVm5SS05jOUJsYzVzbQ0KSzNQUHpKdWxHbDl0NlFaTGh5SU4vRTlYTXM1cllidjlJRS9hNkxZeDFzWDVrVXp1VGlBRktza1BEdVFCTUlYTg0KTjhxa1J0TEtRZFpJVklZT2tMOFVxakF1Q1AyRjMwVzlBQ1YrVlNzSGxac21uRFVLRGJ6ekR0T1lsV1FEdWdheA0KZU1hSVVXWEhTekF2TzRtKzJ5c0hKNm9KTlBOVWorT3ZkZ1gyLzl3bGNMa0xydEFkRUNUZlJDTEZnbGNlMEZ0MA==";
				//     token = "a2YyNWh1K3FISmxubTVkU0VRcFFzaW42WFR5YVIwNFM3WGIvTFJNT2pWZHB2RXlBek16UEhtVGw3cEtQN2x0NDJwbC9WbE1EQkpLWkRQWkJxU2FjdktvM2FLYi9NZnR5cWJQZ0dHOVpMRnI3emlqOE9NZUg1NVk5a09BYVcvdVRYUzFFZ2NOQ3VVTWFra01rWlZzUWFGTkdKMExiODZwOW04MVdHckd5OERvPQ==";
				// }
				const jsonString = JSON.stringify(params);
				console.log("jsonString====",jsonString);
				const enText = aesEncrypt('111',uuid);
				console.log("enText====",enText);
				// U2FsdGVkX19nQkiMRhTHUEmprQN4XFVTUb/VlZIAQBo=
				// U2FsdGVkX18qsClJHhoTmJTuA+w0lyRvSEuXa/1PX9E=
				
			
					
				const enData = base64Encode(enText);
				console.log("enText=base64Encode===",enData);
				const enRsaText = rsaEncrypt(uuid);
				
				console.log("enRsaText====",enRsaText);
				
				const enBase64Text = base64Encode(enRsaText);
				const enBase64 = base64Encode(enBase64Text);
				
				let req = {
					key: enBase64,
					mgc_data: enData,
					token: token,
				}
				uni.request({
					url:'https://api.jetpso.com/Sv/Question/insert',
					method: 'POST',
					header: {
						'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
						'token': token,
					},
					data: req,
					timeout: 30000,
				}).then(res=>{
					console.log("res====",res);
				}).catch(err=>{
					console.log('err=====',err);
				})
				
			}
		},
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
